import { HttpClient } from '@angular/common/http';
import { Injectable } from '@angular/core';
import { Observable } from 'rxjs';
import { Product } from 'src/app/product';
import { Shipping } from 'src/app/shipping';

@Injectable({
  providedIn: 'root'
})
export class CartService {

  items: Product[] = [];

  constructor(private http: HttpClient) { }

  addToCart(product: Product) {
    this.items.push(product);
  }

  getItems(): Product[] {
    return this.items;
  }

  clearCart() {
    this.items = [];
    return this.items;
  }

  getShippingPrices(): Observable<Shipping[]> {
    return this.http.get<Shipping[]>('/assets/shipping.json');
    // return this.http.get<Shipping[]>('http://localhost:5000/shippings');
  }
}
